<?php
/* 
 * Author: Quan Van Sinh
 * Email: sinhvnb@vietnambiz.com
 */
checkLoginHeader();
checkPermission();
articleAction();

?>
<?php include_once $config ['admin_theme_path'].$config ['admin_theme'].'/header.php'; ?>

<script type="text/javascript" src="/admin/themes/default/js/nicEdit.js"></script>
<script type="text/javascript">
    function viewAddArticle(){
        window.location = "/<?php echo $config ['admin_section']; ?>/article?articleActionType=viewAddArticle";
    }
    function editArticle(id){
        window.location = "/<?php echo $config ['admin_section']; ?>/article?id="+id+"&articleActionType=editArticle";
    }

    function deleteArticle(id,txtAlert){
        if (confirm("Do you want to delete article "+txtAlert+"?")){
            $.ajax({
                url: '/<?php echo $config ['admin_section']; ?>/article',
                type: 'POST',
                data: "id="+id+"&articleActionType=deleteArticle",
                error: function(){
                    alert('Error loading article infomation');
                },
                success: function(){
                    window.location.reload(true);
                }
            });
        }
    }


    $(document).ready(function(){
        setTimeout("closeResultMessages()",5000);
    });

    function closeResultMessages(){
        if ( $("#rsMessages").length > 0 ) {
            document.getElementById('rsMessages').style.display = 'none';
        }
    }

    function closeAlertMessages(id){
        document.getElementById(id).style.display = 'none';
    }

    function submitFormAddEditArticle(type){

        if($("#title").val()==''){
            $("#titleAlert").show();
            setTimeout("closeAlertMessages('titleAlert')",8000);
            $("#title").focus();
            return false;
        }

        if($("#categoryId").val()==''){
            $("#categoryAlert").show();
            setTimeout("closeAlertMessages('categoryAlert')",8000);
            $("#categoryId").focus();
            return false;
        }

        if($("#short_description").val()==''){
            $("#shortDescriptionAlert").show();
            setTimeout("closeAlertMessages('shortDescriptionAlert')",80000);
            $("#short_description").focus();
            return false;
        }
        if($("#description").val()=='' || $("#description").val()=='<br>'){
            $("#descriptionAlert").show();
            setTimeout("closeAlertMessages('descriptionAlert')",80000);
            $("#description").focus();
            return false;
        }
        if(type=='add'){
            document.formAddArticle.submit();
        }
        if(type=='edit'){
            document.formEditArticle.submit();
        }

    }

    function genTags(){
        if($("#title").val()==''){
            $("#titleAlert").show();
            setTimeout("closeAlertMessages('titleAlert')",8000);
            $("#title").focus();
            return false;
        }
        if($("#short_description").val()==''){
            $("#shortDescriptionAlert").show();
            setTimeout("closeAlertMessages('shortDescriptionAlert')",80000);
            $("#short_description").focus();
            return false;
        }
        if($("#description").val()=='' || $("#description").val()=='<br>'){
            $("#descriptionAlert").show();
            setTimeout("closeAlertMessages('descriptionAlert')",80000);
            $("#description").focus();
            return false;
        }
        //        var frequency = new Array();
        //        frequency.push($("#frequency1").val(),$("#frequency2").val(),$("#frequency3").val(),$("#frequency4").val(),$("#frequency5").val(),$("#frequency6").val());
        $.ajax({
            url: '/<?php echo $config ['admin_section']; ?>/gen-tag',
            type: 'POST',
            data: "title=" + $("#title").val() + "&description=" + $("#short_description").val() + "&detail=" + $("#description").val() + "&frequency=" + $("#frequency1").val()+','+$("#frequency2").val()+','+$("#frequency3").val()+','+$("#frequency4").val()+','+$("#frequency5").val()+','+$("#frequency6").val(),
            error: function(){
                alert('Error loading tags infomation!');
            },
            success: function(data){
                $("#keywordAlert").html('<span class="success">Generate tags successful!</span>');
                $("#keywordAlert").show('slow');
                setTimeout("hideKeyWordAlert()",5000);

                $("#tagResult").html(data);
            }
        });


    }
    function clearTags(){
        $("input[name=keyword[]]").val('');
    }
    function addPhotos(place){
        windowphoto = window.open("/<?php echo $config ['admin_section']; ?>/photos?place="+place, "Images manger popup", "width=800,height=600,scrollbars=yes");
    }

    checked=false;
    function checkedAll (formId) {
        var aa= document.getElementById(formId);
        if (checked == false)        {
            checked = true;
        }else{
            checked = false;
        }
        for (var i =0; i < aa.elements.length; i++){
            aa.elements[i].checked = checked;
        }
    }

    function actionMultil(action){
        if(action=='delete'){
            if (confirm("Do you want to delete these articles?")){
                document.getElementById('formView').submit();
            }else{
                document.getElementById('action').value = '';
            }
        }else{
            document.getElementById('formView').submit();
        }
    }

    function statusFilter(){
        document.getElementById('formStatusView').submit();
    }

    function keyword_remove(no){
        if(document.getElementById('removedTags').value==''){
            document.getElementById('removedTags').value = document.getElementById('removedTags').value + document.getElementById('key'+no).value;
        }else{
            document.getElementById('removedTags').value = document.getElementById('removedTags').value + ',' + document.getElementById('key'+no).value;
        }
        document.getElementById('k'+no).innerHTML = '';
        document.getElementById('k'+no).style.display = 'none';
        $("#keywordAlert").hide('slow');
        $("#keywordAlert").html('<span class="success">Remove keyword successful!</span>');
        $("#keywordAlert").show('slow');
        setTimeout("hideKeyWordAlert()",5000);
    }
    function hideKeyWordAlert(){
        $("#keywordAlert").hide('slow');
    }
    function keyword_spam(no){
        if(no!=''){
            if(document.getElementById('removedTags').value==''){
                document.getElementById('removedTags').value = document.getElementById('removedTags').value + document.getElementById('key'+no).value;
            }else{
                document.getElementById('removedTags').value = document.getElementById('removedTags').value + ',' + document.getElementById('key'+no).value;
            }
            $.ajax({
                url: '/<?php echo $config ['admin_section']; ?>/gen-tag',
                type: 'GET',
                data: "keyword=" + document.getElementById('key'+no).value,
                error: function(){
                    alert('Error add spam!');
                },
                success: function(){
                    $("#keywordAlert").hide('slow');
                    document.getElementById('k'+no).innerHTML = '';
                    document.getElementById('k'+no).style.display = 'none';
                    $("#keywordAlert").html('<span class="success">Add to spam successful!</span>');
                    $("#keywordAlert").show('slow');
                    setTimeout("hideKeyWordAlert()",5000);
                }
            });
        }
    }
    function frontPage(id,obj){
        if(id!=''){
            $.ajax({
                url: '/<?php echo $config ['admin_section']; ?>/article',
                type: 'POST',
                data: "id="+id+"&articleActionType=updateFrontPageDate",
                error: function(){
                    alert('Error loading article infomation');
                },
                success: function(data){
                    if(data=='yes'){
                        obj.src = '<? echo $config ['admin_images_url'];?>/icons/circle-green.png';
                        obj.title = 'Hot news actived!';
                    }else if(data=='no'){
                        obj.src = '<? echo $config ['admin_images_url'];?>/icons/circle-red.png';
                        obj.title = 'Not show in Hot news!';
                    }else{
                        window.location.reload(true);
                    }
                }
            });
        }
    }

    function removeAttachFile(attachId){
        valueRemoveAttach = '<input type="hidden" name="removeAttachs[]" value="'+ attachId +'"/>';
        divHtml = valueRemoveAttach + $("#hiddenAttachDiv").html();
        $("#hiddenAttachDiv").html(divHtml);
        $("#removeAttachDiv_"+attachId).remove();
    }
</script>

<div id="wrapper">
    <div id="content" style="width: 98%;">
        <?php
        if($_REQUEST['articleActionType']=='viewAddArticle' OR $_REQUEST['articleActionType']=='editArticle') {
            ?>
        <div id="articleAction">
            <div id="box">
                <div id="rightnow">
                    <h3 class="reallynow">
                        <span>Article Actions</span>
                        <a href="/<?php echo $config ['admin_section']; ?>/article">List article</a><br />
                    </h3>
                </div>
                    <?php
                    if($_REQUEST['articleActionType']=='viewAddArticle') {
                        ?>
                <div id="formAddArticle">
                    <form method="post" action="/<?php echo $config ['admin_section']; ?>/article" id="form" name="formAddArticle" enctype="multipart/form-data" style="padding-top: 10px">
                        <fieldset id="fsAddArticle">
                            <legend>Add article</legend>
                            <table border="0" width="99%">
                                <tbody>
                                    <tr>
                                        <td valign="top">
                                            Title : <span id="titleAlert" style="color:red; font-weight:bold; font-size:12px; display:none;">Please insert article title.</span><br>
                                            <textarea id="title" name="title" rows="1" cols="10" style="clear:both;width: 504px; height:16px; background:none;"></textarea>
                                            <input type="hidden" id="articleActionType" name="articleActionType" value="addArticle"/>
                                            <input type="hidden" id="geography_id" name="geography_id" value=""/>
                                            <br>
                                            Category : <span id="categoryAlert" style="color:red; font-weight:bold; font-size:12px; display:none;">Please select article category.</span><br>
                                            <select id="categoryId" name="categoryId" style="width:512px;">
                                                <option value="">Select category</option>
                                                        <?php
                                                        $category = get_cat_tree(0);
                                                        foreach($category as $k=>$rs) {
                                                            ?>
                                                <option value="<?php echo $rs['id'];?>"><? echo $rs['name'];?></option>
                                                        <?php }?>
                                            </select>
                                            <br>

                                            Image : <div style="width: 250px;">
                                                <input type="hidden" id="image" name="image"/>
                                                <img id="imgDisplay" src="/uploads/noimage.jpg" width="100"/>
                                                <input type="button" onclick="javascript: addPhotos('image');" style="float: right" value="Select image"/>
                                            </div>
                                            <br>
                                            Short description : <span id="shortDescriptionAlert" style="color:red; font-weight:bold; font-size:12px; display:none;">Please input some short descriptions.</span><br>
                                            <div style="margin-bottom:10px">
                                                <textarea id="short_description" name="short_description" rows="2" cols="20"></textarea>
                                            </div>
                                            Description : <span id="descriptionAlert" style="color:red; font-weight:bold; font-size:12px; display:none;">Please input some descriptions.</span><br>
                                            <div id="toGetHeight">
                                                <textarea id="description" name="description" rows="4" cols="40" style="width:631px"></textarea>
                                                <script type="text/javascript">
                                                    //editor
                                                    bkLib.onDomLoaded(function(){
                                                        var descriptionEditor = new nicEditor({fullPanel : true }).panelInstance('description');
                                                        descriptionEditor.addEvent("blur", function() {
                                                            document.getElementById("description").value = descriptionEditor.instanceById("description").getContent();
                                                            $("#tagResult").height($("#toGetHeight").height()+150);
                                                        });
                                                    });
                                                </script>
                                            </div>
                                            <br>
                                            Front page: &nbsp;&nbsp;
                                            <input type="radio" name="front_page" value="yes" /> Yes &nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="front_page" value="no" checked /> No<br><br>
                                            Create Date: <br><input style="width: 200px" type="text" id="createDate" name="createDate" onclick="javascript: NewCssCal('createDate','yyyymmdd','arrow',true,24,false);"/><br><br>
                                            Status : <br>
                                            <select id="status" name="status" style="width:200px;">
                                                <option value="yes">Yes</option>
                                                <option value="pending">Pending</option>
                                                <option value="no">No</option>
                                            </select><br>

                                            Attach multi files: <br>
                                            <input type="file" class="multi" maxlength="10" name="attachs[]"/>
                                            <div id="imageList"></div>
                                            <div align="center">
                                                <input type="button" value="Create article" name="addArticleSubmit" id="addArticleSubmit" onclick="javascript: submitFormAddEditArticle('add');"/>

                                                <input type="reset" id="AddArticleReset"/>
                                            </div><br>

                                        </td>
                                        <td valign="top" width="245px">
                                            <input type="button" value="Generate tags" onclick="javascript: genTags();"/>&nbsp;&nbsp;
                                            <input type="button" value="Clear tags" onclick="javascript: clearTags();"/><br>
                                            <fieldset id="fsAddArticle">
                                                <legend>Frequency</legend>
                                                <select style="width:72px" name="frequency[1]" id="frequency1" gtbfieldid="6">
                                                    <option value="-1">1 Word</option>
                                                    <option value="1">1</option>
                                                    <option value="2">2</option>
                                                    <option value="3">3</option>
                                                    <option value="4">4</option>
                                                    <option value="5">5</option>
                                                    <option value="6">6</option>
                                                    <option value="7">7</option>
                                                    <option value="8">8</option>
                                                </select>
                                                <select style="width:72px" name="frequency[2]" id="frequency2" gtbfieldid="7">
                                                    <option value="-1">2 Word</option>
                                                    <option value="1">1</option>
                                                    <option value="2">2</option>
                                                    <option value="3">3</option>
                                                    <option value="4">4</option>
                                                    <option value="5">5</option>
                                                    <option value="6">6</option>
                                                    <option value="7">7</option>
                                                    <option value="8">8</option>
                                                </select>
                                                <select style="width:72px" name="frequency[3]" id="frequency3" gtbfieldid="8">
                                                    <option value="-1">3 Word</option>
                                                    <option value="1">1</option>
                                                    <option value="2">2</option>
                                                    <option value="3">3</option>
                                                    <option value="4">4</option>
                                                    <option value="5">5</option>
                                                    <option value="6">6</option>
                                                    <option value="7">7</option>
                                                    <option value="8">8</option>
                                                </select>
                                                <select style="width:72px" name="frequency[4]" id="frequency4" gtbfieldid="9">
                                                    <option value="-1">4 Word</option>
                                                    <option value="1">1</option>
                                                    <option value="2">2</option>
                                                    <option value="3">3</option>
                                                    <option value="4">4</option>
                                                    <option value="5">5</option>
                                                    <option value="6">6</option>
                                                    <option value="7">7</option>
                                                    <option value="8">8</option>
                                                </select>
                                                <select style="width:72px" name="frequency[5]" id="frequency5" gtbfieldid="10">
                                                    <option value="-1">5 Word</option>
                                                    <option value="1">1</option>
                                                    <option value="2">2</option>
                                                    <option value="3">3</option>
                                                    <option value="4">4</option>
                                                    <option value="5">5</option>
                                                    <option value="6">6</option>
                                                    <option value="7">7</option>
                                                    <option value="8">8</option>
                                                </select>
                                                <select style="width:72px" name="frequency[6]" id="frequency6" gtbfieldid="11">
                                                    <option value="-1">6 Word</option>
                                                    <option value="1">1</option>
                                                    <option value="2">2</option>
                                                    <option value="3">3</option>
                                                    <option value="4">4</option>
                                                    <option value="5">5</option>
                                                    <option value="6">6</option>
                                                    <option value="7">7</option>
                                                    <option value="8">8</option>
                                                </select>
                                            </fieldset>
                                            <div style="height:20px">
                                                <div id="keywordAlert" style="text-align: center;"></div>
                                                <input type="hidden" name="removedTags" id="removedTags"/>
                                            </div>
                                            <hr style="margin-bottom:5px">
                                            <div id="tagResult" style="width: 99%; height: 490px;overflow-x:hidden;overflow-y:scroll;"></div>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </fieldset>
                    </form>
                </div>
                    <?php
                    }else {//edit article
                        $rsEdit = editArticle($_GET['id']);
                        $rsEditAttach = getArticleAttachs($_GET['id']);
                        ?>

                <div id="formEditArticle">
                    <form method="post" action="/<?php echo $config ['admin_section']; ?>/article/<?php echo $_SESSION['articlePageEdit']; ?>" id="form" name="formEditArticle" enctype="multipart/form-data" style="padding-top: 10px">
                        <fieldset id="fsEditArticle">
                            <legend>Edit article</legend>
                            <table border="0" width="99%">
                                <tbody>
                                    <tr>
                                        <td valign="top">
                                            Title : <span id="titleAlert" style="color:red; font-weight:bold; font-size:12px; display:none;">Please insert article title.</span><br>
                                            <textarea id="title" name="title" rows="1" cols="10" style="width: 504px; height:16px; background:none;"><?php echo $rsEdit['rsArticle']['title']; ?></textarea>
                                            <input type="hidden" id="articleActionType" name="articleActionType" value="updateArticle"/>
                                            <input type="hidden" name="id" value="<?php echo $rsEdit['rsArticle']['id']; ?>"/>
                                            <br>
                                            Category : <span id="categoryAlert" style="color:red; font-weight:bold; font-size:12px; display:none;">Please select article category.</span><br>
                                            <select id="categoryId" name="categoryId" style="width:400px;">
                                                <option value="">Select category</option>
                                                        <?php
                                                        $category = get_cat_tree(0);
                                                        foreach($category as $k=>$rs) {

                                                            if($rs['id']==$rsEdit['rsArticle']['cat_id']) {
                                                                ?>
                                                <option value="<?php echo $rs['id'];?>" selected><? echo $rs['name'];?></option>
                                                            <?php
                                                            }else {
                                                                ?>
                                                <option value="<?php echo $rs['id'];?>"><? echo $rs['name'];?></option>
                                                            <?php
                                                            }
                                                        }
                                                        ?>
                                            </select>
                                            <br>
                                            Image : <div style="width: 250px;">
                                                <input type="hidden" id="image" name="image" value="<?php echo $rsEdit['rsArticle']['image']; ?>"/>
                                                <img id="imgDisplay" src="<?php echo $rsEdit['rsArticle']['image']; ?>" width="100"/>
                                                <input type="button" onclick="javascript: addPhotos('image');" style="float: right" value="Select image"/>
                                            </div>
                                            <br>
                                            Short description : <span id="shortDescriptionAlert" style="color:red; font-weight:bold; font-size:12px; display:none;">Please input some short descriptions.</span><br>
                                            <div style="margin-bottom:10px">
                                                <textarea id="short_description" name="short_description" rows="2" cols="20"><?php echo $rsEdit['rsArticle']['short_description']; ?></textarea>
                                            </div>
                                            Description : <span id="descriptionAlert" style="color:red; font-weight:bold; font-size:12px; display:none;">Please input some descriptions.</span><br>
                                            <div id="toGetHeight">
                                                <textarea id="description" name="description" rows="4" cols="40" style="width:631px"><?php echo $rsEdit['rsArticle']['description']; ?></textarea>
                                                <script type="text/javascript">
                                                    //editor
                                                    bkLib.onDomLoaded(function(){
                                                        var descriptionEditor = new nicEditor({fullPanel : true }).panelInstance('description');
                                                        descriptionEditor.addEvent("blur", function() {
                                                            document.getElementById("description").value = descriptionEditor.instanceById("description").getContent();
                                                            $("#tagResult").height($("#toGetHeight").height()+500);
                                                        });
                                                        $("#tagResult").height($("#toGetHeight").height()+500);
                                                    });
                                                </script>
                                            </div>
                                            <br>
                                                    <?php
                                                    if($rsEdit['rsArticle']['front_page']=='yes') {
                                                        $front_pageYes = 'checked';
                                                        $front_pageNo = '';
                                                    }elseif($rsEdit['rsArticle']['front_page']=='no') {
                                                        $front_pageYes = '';
                                                        $front_pageNo = 'checked';
                                                    }
                                                    ?>
                                            Front page: &nbsp;&nbsp;
                                            <input type="radio" name="front_page" value="yes" <?php echo $front_pageYes;?> /> Yes &nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="front_page" value="no" <?php echo $front_pageNo;?> /> No<br><br>
                                            Create Date: <br><input style="width: 200px" type="text" id="createDate" name="createDate" value="<?php echo $rsEdit['rsArticle']['create_date'];?>" onclick="javascript: NewCssCal('createDate','yyyymmdd','arrow',true,24,false);"/><br><br>
                                            Status : <br>
                                            <select id="status" name="status" style="width:200px;">
                                                        <?php

                                                        if($rsEdit['rsArticle']['status']=='yes') {
                                                            echo '<option selected="selected" value="yes">Yes</option>';
                                                            echo '<option value="pending">Pending</option>';
                                                            echo '<option value="no">No</option>';
                                                        }else {
                                                            if($rsEdit['rsArticle']['status']=='pending') {
                                                                echo '<option value="yes">Yes</option>';
                                                                echo '<option selected="selected" value="pending">Pending</option>';
                                                                echo '<option value="no">No</option>';
                                                            }else {
                                                                echo '<option value="yes">Yes</option>';
                                                                echo '<option value="pending">Pending</option>';
                                                                echo '<option selected="selected" value="no">No</option>';
                                                            }
                                                        }
                                                        ?>
                                            </select><br>

                                            Attach multi files: <br>
                                            <input type="file" class="multi" maxlength="10" name="attachs[]"/>
                                            <div id="hiddenAttachDiv" style="display:none"></div>
                                            <div id="removeImageList">
                                                        <?php
                                                        while($rs=$DB->fetch_array($rsEditAttach)) {
                                                            ?>
                                                <div id="removeAttachDiv_<?php echo $rs['id'];?>">
                                                    <a class="MultiFile-remove" href="#MultiFile1_wrap" onclick="removeAttachFile('<?php echo $rs['id'];?>');">x</a>
                                                    <span class="MultiFile-title" title="File selected: <?php echo $rs['real_filename'];?>"><?php echo $rs['real_filename'];?></span>
                                                </div>
                                                        <?php
                                                        }
                                                        ?>
                                            </div>
                                            <div id="imageList"></div>
                                            <div align="center">
                                                <input type="button" value="Update article" name="editArticleSubmit" id="editArticleSubmit" onclick="javascript: submitFormAddEditArticle('edit');"/>
                                            </div><br>

                                        </td>
                                        <td valign="top" width="245px">
                                            <b>Tags:</b><br>
                                            <div id="tagResult" style="width: 99%; height: 490px;overflow-x:hidden;overflow-y:scroll;">
                                                        <?php
                                                        $html = '';
                                                        $i=1;
                                                        while($rs=$DB->fetch_array($rsEdit['rsTags'])) {
                                                            $html.='<div id="k'.$i.'"><input id="key'.$i.'" type="text" size="25" value="'.$rs['tags'].'" name="keyword[]" class="textbox"/>';
                                                            $html.='<span class="keyword_remove" onclick="keyword_remove('.$i.');">Re</span> ';
                                                            $html.='<span class="keyword_spam" onclick="keyword_spam('.$i.');">Sp</span></div>';
                                                            $i++;
                                                        }
                                                        $html.='<div id="k'.$i.'"><input id="key'.$i.'" type="text" size="25" value="" name="keyword[]" class="textbox"/>';
                                                        $html.='<span class="keyword_remove" onclick="keyword_remove('.$i.');">Re</span> ';
                                                        $html.='<span class="keyword_spam" onclick="keyword_spam('.$i.');">Sp</span></div>';
                                                        $i=$i+1;
                                                        $html.='<div id="k'.$i.'"><input id="key'.$i.'" type="text" size="25" value="" name="keyword[]" class="textbox"/>';
                                                        $html.='<span class="keyword_remove" onclick="keyword_remove('.$i.');">Re</span> ';
                                                        $html.='<span class="keyword_spam" onclick="keyword_spam('.$i.');">Sp</span></div>';
                                                        $i=$i+1;
                                                        $html.='<div id="k'.$i.'"><input id="key'.$i.'" type="text" size="25" value="" name="keyword[]" class="textbox"/>';
                                                        $html.='<span class="keyword_remove" onclick="keyword_remove('.$i.');">Re</span> ';
                                                        $html.='<span class="keyword_spam" onclick="keyword_spam('.$i.');">Sp</span></div>';
                                                        $i=$i+1;
                                                        $html.='<div id="k'.$i.'"><input id="key'.$i.'" type="text" size="25" value="" name="keyword[]" class="textbox"/>';
                                                        $html.='<span class="keyword_remove" onclick="keyword_remove('.$i.');">Re</span> ';
                                                        $html.='<span class="keyword_spam" onclick="keyword_spam('.$i.');">Sp</span></div>';
                                                        echo $html;
                                                        ?>
                                                <input type="hidden" name="removedTags" id="removedTags"/>
                                            </div>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </fieldset>
                    </form>
                </div>

                    <?php
                    }
                    ?>
            </div>
            <div style="height:10px"></div>
        </div>
        <?php
        }else {
            ?>

        <div id="rightnow">
            <h3 class="reallynow">
                <span>Search</span>
                <br />
            </h3>
            <div class="youhave">
                <form method="get" action="/<?php echo $config ['admin_section']; ?>/article" id="form" name="form" enctype="multipart/form-data" style="padding-top: 10px">

                    <label for="searchKeyword">Keyword : </label>
                    <input style="width: 200px" type="text" id="searchKeyword" name="searchKeyword" value="<?php echo htmlentities($_GET['searchKeyword']); ?>"/>
                    <input type="hidden" id="articleActionType" name="articleActionType" value="searchArticle"/>
                    <br>
                    <label for="date">Date : </label>
                    <input style="width: 200px" type="text" id="dateFrom" name="dateFrom" value="<?php echo $_GET['dateFrom']; ?>" onclick="javascript: NewCssCal('dateFrom','yyyymmdd','arrow')"/>
                    To
                    <input style="width: 200px" type="text" id="dateTo" name="dateTo" value="<?php echo $_GET['dateTo']; ?>" onclick="javascript: NewCssCal('dateTo','yyyymmdd','arrow')"/>
                    <br>
                    <label for="categoryId">Category : </label>
                    <select id="categoryId" name="categoryId" style="width:208px;">
                        <option value="">Select category</option>
                            <?php
                            $category = get_cat_tree(0);
                            foreach($category as $k=>$rs) {
                                if($_GET['categoryId']==$rs['id']) {
                                    echo '<option selected value="'.$rs['id'].'">'.$rs['name'].'</option>';
                                }else {
                                    echo '<option value="'.$rs['id'].'">'.$rs['name'].'</option>';
                                }
                            }
                            ?>
                    </select>
                    <br>

                    <div align="center">
                        <input type="submit" value="Search" name="searchArticleSubmit" id="searchArticleSubmit"/>
                    </div>
                </form>
            </div>
        </div><br>

        <div id="rightnow">
            <form method="post" action="" id="formStatusView">
                <h3 class="reallynow">
                    <span>Articles</span>
                    <span style="float: right;">

                        <select name="status" style="width:150px; padding:0px;" onchange="javascript: statusFilter();">
                                <?php
                                if(isset($_POST['status'])) {
                                    $_SESSION['articleStatusFilter'] = $_POST['status'];
                                }
                                if($_SESSION['articleStatusFilter']=='yes') {
                                    echo '  <option value="">View by status ( all )</option>
                                            <option selected="selected" value="yes">Yes only</option>
                                            <option value="pending">Pending only</option>
                                            <option value="no">No only</option>';
                                }elseif($_SESSION['articleStatusFilter']=='pending') {
                                    echo '  <option value="">View by status ( all )</option>
                                            <option value="yes">Yes only</option>
                                            <option selected="selected" value="pending">Pending only</option>
                                            <option value="no">No only</option>';
                                }elseif($_SESSION['articleStatusFilter']=='no') {
                                    echo '  <option value="">View by status ( all )</option>
                                            <option value="yes">Yes only</option>
                                            <option value="pending">Pending only</option>
                                            <option selected="selected" value="no">No only</option>';
                                }else {
                                    echo '  <option value="">View by status ( all )</option>
                                            <option value="yes">Yes only</option>
                                            <option value="pending">Pending only</option>
                                            <option value="no">No only</option>';
                                }
                                ?>
                        </select>
                        <input type="hidden" id="articleActionType" name="articleActionType" value="statusFilter"/>
                        <a class="add" href="javascript: addPhotos('');">Add images</a> <a class="add" href="javascript: viewAddArticle();">Add article</a>

                    </span>
                    <br />
                </h3>
            </form>
            <div class="youhave">
                <form method="post" action="" id="formView">
                    <div id="rsMessages" style="text-align: center;"><? if(isset($_SESSION['rsMessages'])) {echo $_SESSION['rsMessages']; $_SESSION['rsMessages']='';} ?></div>
                    <table width="100%">
                        <tbody>
                            <tr height="35px">
                                <td width="40px">&nbsp;</td>
                                <td><b>Title</b></td>
                                <td width="125px"><b>Category</b></td>
                                <td width="60px"><b>Status</b></td>
                                <td width="80px" align="center"><b>Action</b></td>
                            </tr>
                                <?php
                                if(isset($_POST['status']) AND $_POST['status']!='') {
                                    $status = " WHERE a.status='".filter($_POST['status'])."' ";
                                    $rsAllArticle = getAllArticle($config ['total_article_on_admin'],$status);
                                }else {
                                    $rsAllArticle = getAllArticle($config ['total_article_on_admin']);
                                }
                                $i=0;
                                while($rs=$DB->fetch_array($rsAllArticle['rs'])) {
                                    $i++;
                                    if($rs['front_page']=='yes') {
                                        $frontPageImg = 'circle-green.png';
                                        $frontPageTitle = 'Hot news actived!';
                                    }else {
                                        $frontPageImg = 'circle-red.png';
                                        $frontPageTitle = 'Not show in Hot news!';
                                    }
                                    ?>
                            <tr>
                                <td class="a-center"><? echo $i;?></td>
                                <td>&nbsp;&nbsp;<a href="/<?php echo $config ['admin_section']; ?>/detail?id=<?php echo $rs['id'];?>&keepThis=true&TB_iframe=true&height=600&width=800" title="<? echo $rs['title'];?>" class="thickbox"><? echo stripslashes($rs['title']);?></a></td>
                                <td>&nbsp;&nbsp;<a href="/<?php echo $config ['admin_section']; ?>/article&articleActionType=searchArticle&categoryId=<?php echo $rs['cat_id'];?>&searchArticleSubmit=Search"><? echo $rs['category_name'];?></a></td>
                                <td>&nbsp;&nbsp;<? echo ucfirst($rs['status']);?></td>
                                <td valign="middle"><input type="checkbox" id="multiArticleId[]" name="multiArticleId[]" value="<?php echo $rs['id'];?>">
                                    <a href="javascript: void(0);"><img onclick="javascript: frontPage('<?php echo $rs['id'];?>',this);" height="16" width="16" title="<?php echo $frontPageTitle;?>" src="<? echo $config ['admin_images_url'];?>/icons/<?php echo $frontPageImg;?>"/></a>
                                    <a href="javascript: editArticle('<?php echo $rs['id'];?>');"><img height="16" width="16" title="Edit article" src="<? echo $config ['admin_images_url'];?>/icons/page_white_edit.png"/></a>
                                    <a href="javascript: deleteArticle(<?php echo $rs['id'];?>,'<? echo $rs['title'];?>');"><img height="16" width="16" title="Delete article" src="<?php echo $config ['admin_images_url'];?>/icons/page_white_delete.png"/></a>
                                </td>
                            </tr>
                                <?php }?>
                        </tbody>
                    </table>
                    <div style="text-align: right">
                        <b>With selected items:</b>
                        <select id="action" name="action" onchange="javascript: actionMultil(this.value);" style="width:120px; padding:0px;">
                            <option value="">Select action</option>
                            <option value="delete">Delete</option>
                            <option value="yes">Set status to yes</option>
                            <option value="pending">Set status to pending</option>
                            <option value="no">Set status to no</option>
                        </select>&nbsp;&nbsp;&nbsp;
                        <b>Select all/Unselect all:</b>
                        <input type="checkbox" name="checkall" onclick="javascript: checkedAll('formView');">
                        <input type="hidden" id="articleActionType" name="articleActionType" value="actionMultil"/>
                    </div>
                </form>
            </div>
            <div class="linepagination">
                <div class="pagination">
                    <ul>
                            <?php
                            $totalRows =  $rsAllArticle['totalRows'];
                            $totalPages = ceil($totalRows/$config ['total_article_on_admin']);
                            echo pagingAdmin($config ['page'],$totalPages,'','');
                            ?>
                    </ul>
                </div>

            </div>
        </div>

        <?php
        }
        ?>
    </div>
</div>
<?php include_once $config ['admin_theme_path'].$config ['admin_theme'].'/footer.php'; ?>